package com.app.service.Impl;

import com.app.mapper.TownMapper;
import com.app.model.TownshipModel;
import com.app.service.TownService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TownServiceImpl implements TownService {
    @Autowired
    private TownMapper townMapper;

    @Override
    public List<TownshipModel> getTownList() {
        QueryWrapper<TownshipModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        return townMapper.selectList(queryWrapper);
    }

    @Override
    public void update(TownshipModel townshipModel) {
        townMapper.updateById(townshipModel);
    }

    @Override
    public void insert(TownshipModel townshipModel) {
        townMapper.insert(townshipModel);
    }

    @Override
    public void delete(Integer id) {
        townMapper.deleteById(id);
    }

    @Override
    public void updateTownStatus(Integer id, Integer status) {
        TownshipModel model = new TownshipModel();
        model.setId(id);
        model.setStatus(status);
        townMapper.updateById(model);
    }
}
